package com.ptu.spzx.manager.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ptu.spzx.model.entity.system.SysDept;
import com.ptu.spzx.model.entity.system.SysUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SysDeptMapper extends BaseMapper<SysDept> {
    int selectCountById(Long id);

    void deleteDept(Long id);

    void updateDept(SysDept sysDept);

    void saveDept(SysDept sysDept);

    List<SysDept> findDeptByUserId(Long userId);

    List<SysDept> selectAll();

    @Select("SELECT dept_name FROM sys_dept WHERE dept_name LIKE CONCAT('%', #{keyword}, '%') AND is_deleted=0")
    List<String> selectDeptsByNameLike(String keyword);

    @Select("SELECT * FROM sys_dept WHERE dept_name = #{deptName} AND is_deleted=0")
    SysDept selectDeptsByName(String deptName);

    @Select("SELECT * FROM sys_dept WHERE id=#{parentId} AND is_deleted=0")
    SysDept selectParentId(Long parentId);

    @Select("SELECT * FROM sys_dept WHERE parent_id=#{id} AND is_deleted=0")
    List<SysDept> selectSonId(Integer id);

    @Select("SELECT id FROM sys_dept WHERE parent_id=#{id} AND is_deleted=0")
    List<Integer> selectSonIdS(Long id);

    @Select("SELECT * FROM sys_dept WHERE id=#{id} AND is_deleted=0")
    SysDept selectDeptId(Long id);
}
